package cn.wk.servlet;

import cn.wk.services.CourseServices;
import cn.wk.services.impl.CourseServicesImpl;
import cn.wk.util.JsonRes;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/coureseadd")
public class Servletcoureseadd extends HttpServlet {
    private static CourseServices cs=new CourseServicesImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            request.setCharacterEncoding("utf-8");
        String couid =request.getParameter("couid");
        String couname = request.getParameter("couname");
        int  tid =Integer.parseInt(request.getParameter("tid"));
        int b=0;
        if(couid!=null){
            int cid=Integer.parseInt(couid);
             b= cs.MidffCourse(couname,tid,cid);
        }else{
            b= cs.AddCourse(couname,tid);
        }

        if(b>0)
            response.getWriter().println(JsonRes.res());
        else
            response.getWriter().println(JsonRes.error());

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
